//设置全局性的Ajax带参数cookie
	$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
    options.xhrFields = {
        withCredentials: true
    }
});

/**
 * 页面加载完成自动执行
 */
window.onload =function() {
	var pathName = window.location.pathname;
	if (pathName.indexOf("/login.html") != -1) {//当访问login。html
		return;
	}else{
		let localToken = globalData.getCurToken();
	if (localToken == null) {
			window.top.location.href = globalData.pre + "login.html"; // 登录页面;
	} else { 
		//如果token不为空,则执行token校验
		$.ajax({
			url: globalData.server + "test",
			data: {
				token: localToken
			},
			type: "get",
			dataType: "text",
			success(result) {
				if (result != "ok") { //token无效	
					layer.msg("未登录，请先登录",function(){
			window.top.location.href = globalData.pre + "login.html"; // 登录页面;
		});
				} else {
					console.log();
					if (pathName.indexOf(globalData.pre) != -1) {
						
							window.top.location.href = globalData.pre + "index.html"
						
					}
				}

			}
		});
	}
	}
	
};



